<?php
// 搜索接口
include_once 'conn.php';
$id = $_GET['id']; //子订单id
// 查询子订单是否只有一条记录，是就连同大订单一起删除
$sql = $db -> query("SELECT * FROM order_goods WHERE order_user_id = 
                    (SELECT order_user_id FROM order_goods WHERE order_goods_id = '$id' )");
if($sql -> num_rows > 1){ //多条记录，只擅长子订单
    $db -> query("DELETE FROM order_goods WHERE order_goods_id = '$id' ");
}else{ //一条记录，先删除大订单，如果先删除小订单，就找不到大订单了
    $db -> query("DELETE FROM order_user WHERE order_user_id = 
                (SELECT order_user_id FROM order_goods WHERE order_goods_id = '$id')");
    $db -> query("DELETE FROM order_goods WHERE order_goods_id = '$id' ");
    
}
$db -> close();
?>